package com.guoguo.api;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.guoguo.base.BaseController;
import com.guoguo.entity.Users;
import com.guoguo.enums.InviteEnum;
import com.guoguo.enums.TaskEnum;
import com.guoguo.enums.UsersEnum;
import com.guoguo.service.IUsersService;
import com.guoguo.service.InviteService;
import com.guoguo.service.UploadService;
import com.guoguo.service.UserTaskInfoService;
import com.guoguo.utils.JsonUtils;
import com.guoguo.utils.StringUtils;

/**
 * Created by Administrator on 2017/10/23 0023.
 */

     /*
                           _ooOoo_
                          o8888888o
                          88" . "88
                          (| -_- |)
                          O\  =  /O
                       ____/`---'\____
                     .'  \\|     |//  `.
                    /  \\|||  :  |||//  \
                   /  _||||| -:- |||||-  \
                   |   | \\\  -  /// |   |
                   | \_|  ''\---/''  |   |
                   \  .-\__  `-`  ___/-. /
                 ___`. .'  /--.--\  `. . __
              ."" '<  `.___\_<|>_/___.'  >'"".
             | | :  `- \`.;`\ _ /`;.`/ - ` : | |
             \  \ `-.   \_ __\ /__ _/   .-` /  /
        ======`-.____`-.___\_____/___.-`____.-'======
                           `=---='
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 佛祖保佑       永无BUG
        */
@RestController
@RequestMapping("/api/invite")
public class InviteController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(InviteController.class);

    @Autowired
    private InviteService inviteService;

    @Autowired
    private IUsersService iUsersService;

    @Autowired
    private UploadService uploadService;
    
    @Autowired
    private UserTaskInfoService userTaskInfoService;

    @ResponseBody
    @RequestMapping(value = "/invite", method = RequestMethod.POST)
    public JSONObject inviteList(@RequestParam String userId, @RequestParam String albId, String imgId) {
//        AliOssUtils
        return returnResult(200, "", "");
    }


    /**
     * 接受邀请接口
     *
     * @param userId
     * @param phone
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/addInvite", method = RequestMethod.POST)
    public JSONObject saveInvite(@RequestParam String userId, @RequestParam String phone) {
        if (!StringUtils.isEmptyString(userId) && !StringUtils.isEmptyString(phone)) {
            Users users = iUsersService.selectByPrimaryKey(userId);
            if (users != null) {
                return inviteService.saveOrUpdateInvite(userId, phone);
            } else {
                return returnResult(UsersEnum.LOGIN_NOT_USER.getId(), "", UsersEnum.LOGIN_NOT_USER.getValue());
            }
        } else {
            return returnResult(InviteEnum.INVITE_ARGS_ERROR.getId(), "", InviteEnum.INVITE_ARGS_ERROR.getValue());
        }
    }

    
    /**
     * 邀请有奖基本数据
     * @param model
     * @return
     */
	@ResponseBody
    @RequestMapping(value = "/invitationAwardBasic", method = RequestMethod.POST)
    public JSONObject invitationAwardBasic(@RequestParam Map<String, String> model) {
    	logger.info("into InviteController invitationAward method");
    	String userId = model.get("userId");
    	String imgId = model.get("imgId");
    	Map<String, String> data = new HashMap<String, String>();
		try {
			data = iUsersService.invitationAwardBasic(userId,imgId);
			return JsonUtils.returnObject(200,data,"true");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return returnResult(TaskEnum.ERROR.getId(), "false", TaskEnum.ERROR.getValue());
		}
        
    }
	
	 /**
     * 邀请有奖二维码数据
     * @param model
     * @return
     */
	@ResponseBody
    @RequestMapping(value = "/invitationAwardQR", method = RequestMethod.POST)
    public JSONObject invitationAwardQR(@RequestParam Map<String, String> model) {
    	logger.info("into InviteController invitationAward method");
    	String userId = model.get("userId");
    	String imgId = model.get("imgId");
    	Map<String, String> data = new HashMap<String, String>();
		try {
			data = iUsersService.invitationAwardQR(userId,imgId);
			return JsonUtils.returnObject(200,data,"true");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return returnResult(TaskEnum.ERROR.getId(), "false", TaskEnum.ERROR.getValue());
		}
        
    }
    

//    @RequestMapping(value="/sharePage",method = RequestMethod.GET)
//    public ModelAndView sharePage(){
//        return returnView("/sharePage",null);
//    }


}
